package com.test.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * Created by Administrator on 2017/5/3.
 * RabbitMq测试---消费者
 */
@Component
@RabbitListener(queues = "hello")
public class Receiver implements MessageListener {
    private static final Log log = LogFactory.getLog(Receiver.class);

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    @Transactional
    public void onMessage(Message message) {
        System.out.println("消费者接收到消息1["+new Date()+"]=======" + message.getBody());
        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("消费者接收到消息2["+new Date()+"]=======" + message.getBody());
        //throw new RuntimeException();
    }
}
